package gob.inei.enaho.view.enaho01;

import java.sql.SQLException;

import util.android.cuestionario.fragment.CuestionarioFragment;
import util.form.respuesta.RegistroImpl;
import gob.inei.enaho.context.AppContext;
import gob.inei.enaho.model.domain.persona.Hogar;
import gob.inei.enaho.model.domain.ubicacion.Conglomerado;
import gob.inei.enaho.model.service.ConglomeradoService;
import gob.inei.enaho.model.service.HogarService;

public abstract class AbstractHogarFragment 
extends CuestionarioFragment {
	
	protected final HogarService hogarService = AppContext.getServices().getHogarService();
	private final ConglomeradoService conglomeradoService = AppContext.getServices().getConglomeradoService();
	
	protected Hogar hogar;
	
	public void setHogar(Hogar hogar) {
		this.hogar = hogar;
	}

	public String getNumHogar() {
		return hogar.getCodigoString();
	}
	
	public String getEstrato() throws SQLException {
		Conglomerado c = conglomeradoService.findById(hogar.getVivienda().getConglomerado().getCodigo());
		return c.getEstrato();
	}
	
	@Override
	protected void guardar(RegistroImpl reg) throws Exception {		
		hogarService.update(hogar,reg);	
	}	
	
}